import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
function sessionStg(state) {
  window.sessionStorage.setItem("state", JSON.stringify(state));
}
export default new Vuex.Store({
  state: {
    isLogin: true, // 是否登录
    activeHeaderMenu: "home", // active底部导航栏
    currentRouterName: "首页" // 当前router的name
  },
  mutations: {
    changeLogin(state, info) {
      state.isLogin = info;
      sessionStg(state);
    },
    changeActiveMenu(state, routerName) {
      state.activeHeaderMenu = routerName;
      sessionStg(state);
    },
    changeCurrentRouterName(state, routerName) {
      state.currentRouterName = routerName;
      sessionStg(state);
    }
  },
  actions: {
    changeLogin(context, info) {
      context.commit("changeLogin", info);
    },
    changeActiveMenu(context, routerName) {
      context.commit("changeActiveMenu", routerName);
    },
    changeCurrentRouterName(context, routerName) {
      context.commit("changeCurrentRouterName", routerName);
    }
  }
});
